package com.lili.core.jdbc.datasource.impl;

import javax.sql.DataSource;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.lili.core.jdbc.datasource.DataSourceEnum;
import com.lili.core.jdbc.datasource.IDataSourceLocator;

public class SpringDataSourceLocator implements IDataSourceLocator,
		ApplicationContextAware {

	@Override
	public DataSource getDataSource(DataSourceEnum definition) {
		return (DataSource) _context.getBean(definition.name(),
				DataSource.class);
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		_context = applicationContext;
	}

	private ApplicationContext _context;
}
